<?php

namespace frontend\components;
use  yii\helpers\Html;

class DataHelper {

    /**
     * 转移特殊字符
     */
    public static function encode($dispaly_text){
        return  Html::encode($dispaly_text);
    }
	/**
	 *分页
	 */
	public static function ipagination($params)
	{
		$ret = [
			'previous'  => true,
			'next'      => true,
			'from'      => 0,
			'end'       => 0,
			'totalPage' => 0,
			'total_page' => 0,
			'current'   => 0,
			'page_size' => intval( $params['page_size'] )
		];
		$total     = (int)$params['total_count'];
		$pageSize  = (int)$params['page_size'];
		$page      = (int)$params['page'];
		$display   = (int)$params['display'];
		$totalPage = (int)ceil($total / $pageSize);
		$totalPage = $totalPage?$totalPage:1;

		if ($page <= 1) {
			$ret['previous'] = false;
		}
		if ($page >= $totalPage) {
			$ret['next'] = false;
		}
		$semi = (int)ceil($display / 2);
		if ($page - $semi > 0) {
			$ret['from'] = $page - $semi;
		} else {
			$ret['from'] = 1;
		}
		if ($page + $semi <= $totalPage) {
			$ret['end'] = $page + $semi;
		} else {
			$ret['end'] = $totalPage;
		}
		$ret['total_count'] = $total;
		$ret['totalPage'] = $totalPage;
		$ret['total_page'] = $totalPage;
		$ret['current']   = $page;
		return $ret;
	}


}